package com.longge;

import java.util.*;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-03-06 23:00
 */
public class LevelOrder {

    public List<List<Integer>> levelOrder(TreeNode root) {
        List<List<Integer>> res = new ArrayList<>();
        if (root == null) return res;
        Deque<TreeNode> queue = new LinkedList<TreeNode>();
        queue.add(root);
        while (!queue.isEmpty()) {
            List<Integer> col = new ArrayList<>();
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode node = queue.poll();
                col.add(node.val);
                if (node.left != null) queue.offer(node.left);
                if (node.right != null) queue.offer(node.right);
            }
            res.add(col);
        }
        return res;
    }

    public static void main(String[] args) {
        String tl = "1111";
        String[] split = tl.split("22");
        System.out.println(Arrays.toString(split));
    }


}
